﻿Public Class ReportUT507
    Inherits System.Web.UI.Page

    Private Property DataSource As Data.DataTable
        Get
            Return Me.Session("datasourceut507")
        End Get
        Set(ByVal value As Data.DataTable)
            Me.Session("datasourceut507") = value
        End Set
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            BL.Report.SetYearList(Me.ddlYear)
        End If
    End Sub

    Protected Sub btnExcel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnExcel.Click

        Dim oincomeFrom As Nullable(Of Decimal) = Nothing
        Dim oincomeTo As Nullable(Of Decimal) = Nothing

        If incomeFrom.Text.Trim <> "" Then oincomeFrom = Convert.ToDecimal(incomeFrom.Text.Trim)
        If incomeTo.Text.Trim <> "" Then oincomeTo = Convert.ToDecimal(incomeTo.Text.Trim)

        'DataSource = BL.Report.ReportUT507(oincomeFrom, oincomeTo)

        'If Me.DataSource Is Nothing OrElse Me.DataSource.Rows.Count = 0 Then
        '    Exit Sub
        'End If

        'Bind(0)

        'Dim dt As DataTable = Me.DataSource
        'dt.Columns.Add("OrderNo")
        'Dim i As Integer = 0
        'For Each dr As DataRow In dt.Rows
        '    i += 1
        '    dr("OrderNo") = i.ToString

        '    If Not IsDBNull(dr("T7")) AndAlso dr("T7").ToString = "S" Then
        '        dr("T7") = "โสด"
        '    ElseIf Not IsDBNull(dr("T7")) AndAlso dr("T7").ToString = "M" Then
        '        dr("T7") = "สมรส"
        '    Else
        '        dr("T7") = ""
        '    End If

        '    'dr("T8") = " " & dr("T8")
        'Next
        'Common.Utility.ExportToSpreadsheet(gvList, dt, "TaxInfo")

        Try
            Response.ClearContent()
            Response.ClearHeaders()
            If BL.Report.ReportUT507Export(Server.MapPath("~/report/UT507.rpt"), Server.MapPath("~/download/"), Response.OutputStream, oincomeFrom, oincomeTo, ddlYear.SelectedValue) Then
                Response.Buffer = True
                Response.AddHeader("Content-Disposition", "inline; filename=TaxInfo.zip")
                Response.ContentType = "application/zip"
                Response.Flush()
                Response.Close()
            Else
                Me.Master.Alert("ไม่สามารถ Export ไฟล์ได้ อาจเกิดจากไม่พบข้อมูลหรือเกิดข้อผิดพลาดในการทำงาน")
            End If
        Catch ex As Exception
            Common.LogError.AddLogException(ex)
            Me.Master.Alert("ไม่สามารถ Export ไฟล์ได้ อาจเกิดจากไม่พบข้อมูลหรือเกิดข้อผิดพลาดในการทำงาน")
        End Try

    End Sub

    Public Shared Function OrderNuber() As String
        Return String.Empty
    End Function

    Private Sub Bind(ByVal pageIndex As Integer)
        Me.gvList.DataSource = DataSource
        Me.gvList.PageIndex = pageIndex
        Me.gvList.DataBind()
    End Sub

End Class